<?php
//用于写各个网站统一的函数
class PublicFunction  {
	function __construct($arr = NULL){
		
	}
	//头部文件
	function  headerFile($get = array()) {
		
		$web_type = empty($get['web_type']) ? 'wondershare': strtolower(trim(htmlspecialchars($get['web_type'])));

		switch ($web_type){
			case 'wondershare':
				//return file_get_contents("http://check.wondershare.com/wondershare.com/httpdocs/library/head.html");
				$str = getDirLevel($get['url'], "httpdocs");
				
				if (substr_count($get['url'], 'support.wondershare.com') > 0) {
					return '<!--#include virtual="'.$str.'library/header.html"-->';
				} else {
					return '<!--#include virtual="'.$str.'library/head.html"-->';
				}
				
				break; 
			case 'iskysoft':
				//return file_get_contents("http://check.wondershare.com/iskysoft.com/httpdocs/library/header.html");
				$str = getDirLevel($get['url'], "httpdocs");
				return '<!--#include virtual="'.$str.'library/header.html"-->';
				break;
				
			case 'aimersoft':
				//return file_get_contents("http://check.wondershare.com/aimersoft.com/httpdocs/library/header.html");
				$str = getDirLevel($get['url'],"httpdocs");
				return '<!--#include virtual="'.$str.'library/header.html"-->';
				break; 
				
			case 'daniusoft':
				//return file_get_contents("http://check.wondershare.com/aimersoft.com/httpdocs/library/header.html");
				$str = getDirLevel($get['url'],"httpdocs");
				return '<!--#include virtual="'.$str.'library/header.html"-->';
				break; 
		}
	}
	
	//脚文件
	function  footerFile($get = array()) {
		
		$web_type = empty($get['web_type']) ? 'wondershare' : trim(htmlspecialchars($get['web_type']));
		switch ($web_type){
			
			case 'wondershare':
				//return file_get_contents("http://check.wondershare.com/wondershare.com/httpdocs/library/footer.html");
				$str = getDirLevel($get['url'],"httpdocs");
				return '<!--#include virtual="'.$str.'library/footer.html"-->';
				break; 
				
			case 'iskysoft':
				//return file_get_contents("http://check.wondershare.com/iskysoft.com/httpdocs/library/footer.html");
				$str = getDirLevel($get['url'],"httpdocs");
				return '<!--#include virtual="'.$str.'library/footer.html"-->';
				break; 
				
			case 'aimersoft':
				//return file_get_contents("http://check.wondershare.com/aimersoft.com/httpdocs/library/footer.html");
				$str = getDirLevel($get['url'],"httpdocs");
				return '<!--#include virtual="'.$str.'library/footer.html"-->';
				break; 
			case 'daniusoft':
				//return file_get_contents("http://check.wondershare.com/aimersoft.com/httpdocs/library/footer.html");
				$str = getDirLevel($get['url'],"httpdocs");
				return '<!--#include virtual="'.$str.'library/footer.html"-->';
				break; 
		}
	}
	

	//替换模板中的变量为Get主要用于分页
	function replaceTemplateAndGet($templates) {

		//以下把字符串转化成php代码
        preg_match_all ("/\<\?php(.*?)\?\>/", $templates, $matches);
		for ($i=0; $i< count($matches[0]); $i++)  {
			
			echo  eval($matches[1][$i]);
		}
		//把php代码为空
	 	preg_match_all ("/\<\?php(.*?)\?\>/", $templates, $matches);
		for ($i=0; $i< count($matches[0]); $i++)  {
			
			$templates = str_replace($matches[0][$i], '', $templates);
		}
		
		//数组 转化成GET
		arr_to_gets($arr);
		return $templates;
	}
}
?>